﻿#include "DlgReportCash.h"
#include <wx/sizer.h>
#include <wx/statbox.h>
#include <wx/stattext.h>
#include <wx/msgdlg.h>
//(*InternalHeaders(DlgUser)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//(*IdInit(DlgUser)
//*)
#define MORNING _T("上午")
#define AFTERNOON      _T("下午")
#define NIGHT       _T("晚上")
#define TIME_OTHER       _T("其他时间段")
const wxString WINDOWS_TEXT = _T("现金流报表");
//控件ID
const long CDlgReportCash::IDC_BTN_EXIT= wxNewId();
const long CDlgReportCash::IDC_BTN_SEARCH= wxNewId();
const long CDlgReportCash::IDC_EDIT_SEARCH= wxNewId();
const long CDlgReportCash::IDC_EDIT_BALANCE= wxNewId();
const long CDlgReportCash::IDC_EDIT_USER= wxNewId();
const long CDlgReportCash::IDC_COMBO_TIME= wxNewId();
const long CDlgReportCash::IDC_COMBO_TYPE= wxNewId();
const long CDlgReportCash::IDC_COMBO_SEARCH= wxNewId();
const long CDlgReportCash::IDC_RICHEDIT_REMARK= wxNewId();
const long CDlgReportCash::IDC_THEDAY= wxNewId();
const long CDlgReportCash::IDC_LIST= wxNewId();
const long CDlgReportCash::IDC_TIMEFROM= wxNewId();
const long CDlgReportCash::IDC_TIMETO= wxNewId();
const long CDlgReportCash::IDC_EDIT_STATIC= wxNewId();

BEGIN_EVENT_TABLE(CDlgReportCash,wxDialog)
    //(*EventTable(DlgUser)
    //*)
END_EVENT_TABLE()

CDlgReportCash::CDlgReportCash(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
    //(*Initialize(DlgUser)
    Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxMINIMIZE_BOX, _T("id"));
    SetClientSize(wxDefaultSize);
    Move(wxDefaultPosition);
    //*)
    SetTitle(WINDOWS_TEXT);
    SetWindowStyle(GetWindowStyle()|wxRESIZE_BORDER|wxCLOSE_BOX|wxMAXIMIZE_BOX|wxMINIMIZE_BOX);
    CreateCtrlAndEvent();
    InitComboBoxAndListCtrl();
}

CDlgReportCash::~CDlgReportCash()
{
    //(*Destroy(DlgUser)
    //*)
}

void CDlgReportCash::CreateCtrlAndEvent()
{
    /////////创建控件并布局
    topSizer_=new wxBoxSizer(wxVERTICAL);//顶层窗口布局,从上到下包含每个了窗口布局

    wxFlexGridSizer *firSize=new wxFlexGridSizer(1,6,0,0);
    firSize->AddGrowableCol(2);
    firSize->AddGrowableCol(4);
    wxBoxSizer *secSize=new wxBoxSizer(wxHORIZONTAL);
    wxFlexGridSizer *fir_secSize=new wxFlexGridSizer(1,2,0,0);
    fir_secSize->AddGrowableCol(0);
    wxBoxSizer *fir_secSize_l=new wxBoxSizer(wxVERTICAL);

    wxBoxSizer *thiSize=new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer *forSize=new wxBoxSizer(wxHORIZONTAL);
    wxStaticBox *staticBox=new wxStaticBox(this,wxID_ANY,wxT("详细数据"));
    wxStaticBoxSizer *fifSize=new wxStaticBoxSizer(staticBox,wxHORIZONTAL);
    staticBox=new wxStaticBox(this,wxID_ANY,wxT("统计信息"));
    wxStaticBoxSizer *sixSize=new wxStaticBoxSizer(staticBox,wxHORIZONTAL);
    wxBoxSizer *bottomSize=new wxBoxSizer(wxHORIZONTAL);
    topSizer_->Add(fir_secSize,0,wxEXPAND|wxALL,0);
    topSizer_->Add(thiSize,0,wxEXPAND|wxALL,0);
    topSizer_->Add(forSize,0,wxEXPAND|wxALL,0);
    topSizer_->Add(fifSize,10,wxEXPAND|wxALL,0);
    topSizer_->Add(sixSize,5,wxEXPAND|wxALL,0);
    topSizer_->Add(bottomSize,0,wxEXPAND|wxALL,0);

    combo_search_=new wxChoice(this,IDC_COMBO_SEARCH);
    combo_time_=new wxComboBox(this,IDC_COMBO_TIME);
    combo_type_=new wxComboBox(this,IDC_COMBO_TYPE);

    btn_Exit_=new wxButton(this,IDC_BTN_EXIT,_T("退出"));
    btn_Search_=new wxButton(this,IDC_BTN_SEARCH,_T("查询"));
    text_search_=new wxTextCtrl(this,IDC_EDIT_SEARCH,wxEmptyString);
    text_balance_=new wxTextCtrl(this,IDC_EDIT_BALANCE,wxEmptyString);
    text_user_=new wxTextCtrl(this,IDC_EDIT_USER,wxEmptyString);
    text_remark_=new wxTextCtrl(this,IDC_RICHEDIT_REMARK,wxEmptyString,wxDefaultPosition,wxSize(120,50),
                                wxTE_PROCESS_ENTER|wxTE_MULTILINE|wxHSCROLL);
    time_=new wxDatePickerCtrl(this,IDC_THEDAY,wxDefaultDateTime,wxDefaultPosition,
                               wxDefaultSize,wxDP_DROPDOWN|wxDP_SHOWCENTURY);
    list_=new wxListCtrl(this,IDC_LIST,wxDefaultPosition,wxDefaultSize,wxLC_REPORT|wxLC_SINGLE_SEL);
    timeto_=new wxDatePickerCtrl(this,IDC_TIMETO,wxDefaultDateTime,wxDefaultPosition,
                                 wxDefaultSize,wxDP_DROPDOWN|wxDP_SHOWCENTURY);
    timefrom_=new wxDatePickerCtrl(this,IDC_TIMEFROM,wxDefaultDateTime,wxDefaultPosition,
                                   wxDefaultSize,wxDP_DROPDOWN|wxDP_SHOWCENTURY);
    text_stat_=new wxTextCtrl(this,IDC_EDIT_STATIC,wxEmptyString,
                              wxDefaultPosition,wxDefaultSize,wxTE_PROCESS_ENTER|wxTE_MULTILINE|wxHSCROLL);
    firSize->AddSpacer(10);
    firSize->Add(new wxStaticText(this,wxID_ANY,_T("从")),1, wxEXPAND|wxALL|wxALIGN_CENTER,5);
    firSize->Add(timefrom_,1, wxEXPAND|wxALL|wxALIGN_CENTER,5);
    firSize->Add(new wxStaticText(this,wxID_ANY,_T("到")),1, wxEXPAND|wxALL|wxALIGN_CENTER,5);
    firSize->Add(timeto_,1, wxEXPAND|wxALL|wxALIGN_CENTER,5);
    firSize->AddSpacer(10);
    secSize->Add(new wxStaticText(this,wxID_ANY,_T("查询类别")),1, wxTILE|wxALL|wxALIGN_RIGHT,5);
    secSize->Add(combo_search_,1, wxEXPAND|wxALL|wxALIGN_CENTER,5);
    secSize->Add(text_search_,1,wxEXPAND|wxALL|wxALIGN_CENTER,5);
    fir_secSize_l->Add(firSize,5,wxTILE|wxALL|wxALIGN_CENTER,5);
    fir_secSize_l->Add(secSize,5,wxEXPAND|wxALL,5);
    fir_secSize->Add(fir_secSize_l,10,wxEXPAND|wxALL|wxALIGN_CENTER,0);
    fir_secSize->Add(btn_Search_,0,wxEXPAND|wxALL|wxALIGN_CENTER,0);
    thiSize->Add(new wxStaticText(this,wxID_ANY,_T("时间")),0,wxFIXED_MINSIZE|wxALL|wxALIGN_RIGHT,5);
    thiSize->Add(time_,1,wxEXPAND|wxALL|wxALIGN_CENTER,5);
    thiSize->AddStretchSpacer(1);
    thiSize->Add(new wxStaticText(this,wxID_ANY,_T("时间段")),0,wxFIXED_MINSIZE|wxALL|wxALIGN_RIGHT,5);
    thiSize->Add(combo_time_,1,wxEXPAND|wxALL|wxALIGN_CENTER,5);
    thiSize->AddStretchSpacer(1);
    thiSize->Add(new wxStaticText(this,wxID_ANY,_T("收支数")),0,wxFIXED_MINSIZE|wxALL|wxALIGN_RIGHT,5);
    thiSize->Add(text_balance_,1,wxEXPAND|wxALL|wxALIGN_CENTER,5);
    forSize->Add(new wxStaticText(this,wxID_ANY,_T("经手人")),0,wxFIXED_MINSIZE|wxALL|wxALIGN_RIGHT,5);
    forSize->Add(text_user_,1,wxEXPAND|wxALL|wxALIGN_CENTER,5);
    forSize->AddStretchSpacer(1);
    forSize->Add(new wxStaticText(this,wxID_ANY,_T("收支类别")),0,wxFIXED_MINSIZE|wxALL|wxALIGN_RIGHT,5);
    forSize->Add(combo_type_,1,wxEXPAND|wxALL|wxALIGN_CENTER,5);
    forSize->AddStretchSpacer(1);
    forSize->Add(new wxStaticText(this,wxID_ANY,_T("备注")),0,wxFIXED_MINSIZE|wxALL|wxALIGN_RIGHT,5);
    forSize->Add(text_remark_,1,wxEXPAND|wxALL|wxALIGN_CENTER,5);
    fifSize->Add(list_,1,wxEXPAND | wxALL,5);
    sixSize->Add(text_stat_,1,wxEXPAND | wxALL,5);
    bottomSize->Add(btn_Exit_,1,wxTILE|wxALL|wxALIGN_CENTER,5);

    SetSizer(topSizer_);//绑定对话框和布局控件
    SetAutoLayout(true);
    topSizer_->Fit(this);//调用对话框大小
    topSizer_->SetSizeHints(this);//设置对话框最小大小

    ///////创建事件
    Connect(IDC_BTN_EXIT,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CDlgReportCash::OnBnClickedBtnExit);
    Connect(IDC_BTN_SEARCH,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CDlgReportCash::OnBnClickedBtnSearch);
    Connect(IDC_LIST,wxEVT_COMMAND_LIST_ITEM_SELECTED,(wxObjectEventFunction)&CDlgReportCash::OnNMClickList);
    wxLogDebug(_T("CreateCtrl"));
}

void CDlgReportCash::InitComboBoxAndListCtrl()
{
    wxChoice *pchoice=wxDynamicCast(FindWindowById(IDC_COMBO_SEARCH),wxChoice);
    wxListCtrl *pList=wxDynamicCast(FindWindowById(IDC_LIST),wxListCtrl);
    pList->SetSingleStyle(wxLC_REPORT);
    pList->SetSingleStyle(wxLC_SINGLE_SEL);
    const vector<pair<wxString,wxString> >&chs_fileds_name=GetFiled_CHS_Name(_T("name_VcashFull"));
    auto it=chs_fileds_name.cbegin();
    for (; it!=chs_fileds_name.cend(); ++it) {
        wxLogDebug(_T("%s "),it->first);
        pchoice->Append(it->first);
        pList->InsertColumn(pList->GetColumnCount(),it->first,wxLIST_FORMAT_LEFT,wxLIST_AUTOSIZE);
    }
    wxComboBox *pBox=wxDynamicCast(FindWindowById(IDC_COMBO_TIME),wxComboBox);
    pBox->Append(MORNING);
    pBox->Append(AFTERNOON);
    pBox->Append(NIGHT);
    pBox->Append(TIME_OTHER);
    pBox=wxDynamicCast(FindWindowById(IDC_COMBO_TYPE),wxComboBox);
    wxString sql=_T("where typeid like '1%'");
    vector<pair<wxString,int> > typenameandid_=GetTypeName_ID(sql);
    vector<pair<wxString,int> >::const_iterator nameidit=typenameandid_.begin();
    for (; nameidit!=typenameandid_.end(); ++nameidit) {
        pBox->Append(nameidit->first);
    }
    wxDateTime cur_time=wxDateTime::Now();
    cur_time.SetDay(1);//设为1号
    wxDatePickerCtrl *pDT=wxDynamicCast(FindWindowById(IDC_TIMEFROM),wxDatePickerCtrl);
    pDT->SetValue(cur_time);
    cur_time.Add(wxDateSpan::Month());//加一个月
    cur_time.Subtract(wxDateSpan::Day());//减一天，即为当月最后一天
    pDT=wxDynamicCast(FindWindowById(IDC_TIMETO),wxDatePickerCtrl);
    pDT->SetValue(cur_time);
    wxLogDebug(_T("InitComboBoxAndListCtrl"));
}


void CDlgReportCash::OnBnClickedBtnSearch(wxCommandEvent& event)
{
    wxBusyCursor waticursor;
    wxChoice *pBox=wxDynamicCast(FindWindowById(IDC_COMBO_SEARCH),wxChoice);
    int index=pBox->GetSelection();
    wxString strComboTextFirst,strComboTextSecond;
    if (index != wxNOT_FOUND) {
        strComboTextFirst=pBox->GetString(index);
    }
    wxListCtrl *pList=wxDynamicCast(FindWindowById(IDC_LIST),wxListCtrl);
    pList->DeleteAllItems();
    wxDatePickerCtrl *pDT=wxDynamicCast(FindWindowById(IDC_TIMETO),wxDatePickerCtrl);
    wxString time_to=pDT->GetValue().FormatISODate();
    pDT=wxDynamicCast(FindWindowById(IDC_TIMEFROM),wxDatePickerCtrl);
    wxString time_from=pDT->GetValue().FormatISODate();

    const vector<pair<wxString,wxString> >&chs_filed_name=GetFiled_CHS_Name(_T("name_VcashFull"));
    if (chs_filed_name.empty()) {
        return;
    }
    auto it=chs_filed_name.cbegin();
    wxString sql=_T("select ");
    for (; it!=chs_filed_name.cend(); ++it) {
        if (strComboTextFirst==it->first) {
            strComboTextSecond=it->second;
        }
        sql+=it->second+_T(",");
    }
    sql=sql.substr(0,sql.length()-1);
    sql+=_T(" from VcashFull where date(theDay) >= date(@pa1) and date(theDay) <=date(@pa2) ");
    wxString incomesql=_T("select sum(balance) as income from  VcashFull where date(theDay) >= date(@pa1) and date(theDay) <=date(@pa2) ");
    wxString expendsql=_T("select sum(balance)*-1 as expend from  VcashFull where date(theDay) >= date(@pa1) and date(theDay) <=date(@pa2) ");
    wxString balancesql=_T("select sum(balance) as thebalance from  VcashFull where date(theDay) >= date(@pa1) and date(theDay) <=date(@pa2) ");
    wxTextCtrl *pText=wxDynamicCast(FindWindowById(IDC_EDIT_SEARCH),wxTextCtrl);
    wxString csEditText=pText->GetValue();
    csEditText.Trim(true);
    csEditText.Trim(false);
    if (!csEditText.IsEmpty() && !strComboTextFirst.IsEmpty()) {
        sql+=_T(" and ")+strComboTextSecond;
        sql+=_T(" like  '%")+csEditText+_T("%'");
        incomesql+=_T(" and ")+strComboTextSecond;
        incomesql+=_T(" like  '%")+csEditText+_T("%'");
        expendsql+=_T(" and ")+strComboTextSecond;
        expendsql+=_T(" like  '%")+csEditText+_T("%'");
        balancesql+=_T(" and ")+strComboTextSecond;
        balancesql+=_T(" like  '%")+csEditText+_T("%'");
    }
    sql+=_T(" order by theday desc ");
    incomesql+=_T(" and balance>=0 ");
    expendsql+=_T(" and balance<0 ");
    wxLogDebug(_T("sql=%s,%s,%s"),sql,time_from,time_to);
    wxLogDebug(_T("incomesql=%s"),incomesql);
    wxLogDebug(_T("expendsql=%s"),expendsql);
    wxLogDebug(_T("balancesql=%s"),balancesql);
    ////////明细查询
    sqlite3_stmt *conCate,*conIncome,*conExpend,*conBalance;
    if(sqlite3_prepare_v2(g_db,ToDefaultConv(sql),LenDefaultConv(sql),&conCate,NULL)==SQLITE_OK) {
        int index1 = sqlite3_bind_parameter_index(conCate, "@pa1");
        if(sqlite3_bind_text(conCate, index1, ToDefaultConv(time_from), LenDefaultConv(time_from), SQLITE_STATIC)!=SQLITE_OK) {
            wxLogDebug(_T("sqlite3_bind_text on m_keyvalue_.first Error on. %s"), sqlite3_errmsg(g_db));
        }
        index1 = sqlite3_bind_parameter_index(conCate, "@pa2");
        if(sqlite3_bind_text(conCate, index1, ToDefaultConv(time_to), LenDefaultConv(time_to), SQLITE_STATIC)!=SQLITE_OK) {
            wxLogDebug(_T("sqlite3_bind_text on ntimeslot Error on. %s"), sqlite3_errmsg(g_db));
        }
        int row_count=0;
        while(sqlite3_step(conCate)==SQLITE_ROW) {
            pList->InsertItem(row_count, _T(""));
            pList->SetItem(row_count,0,wxString((const char*)sqlite3_column_text(conCate,0), DefaultConv));
            pList->SetItem(row_count,1,wxString((const char*)sqlite3_column_text(conCate,1), DefaultConv));
            pList->SetItem(row_count,2,wxString((const char*)sqlite3_column_text(conCate,2), DefaultConv));
            pList->SetItem(row_count,3,wxString((const char*)sqlite3_column_text(conCate,3), DefaultConv));
            pList->SetItem(row_count,4,wxString((const char*)sqlite3_column_text(conCate,4), DefaultConv));
            pList->SetItem(row_count,5,wxString((const char*)sqlite3_column_text(conCate,5), DefaultConv));
            pList->SetItem(row_count++,6,wxString((const char*)sqlite3_column_text(conCate,6), DefaultConv));
        }
    } else {
        wxLogDebug(_T("Error on sqlite3_prepare_v2: %s"), sqlite3_errmsg(g_db));
    }
    if (sqlite3_finalize(conCate) != SQLITE_OK) {
        wxLogDebug(_T("Error on sqlite3_finalize: %s"), sqlite3_errmsg(g_db));
    }
    double dincome=0.,dexpend=0.,dbalance=0.;
    //收入查询
    if(sqlite3_prepare_v2(g_db,ToDefaultConv(incomesql),LenDefaultConv(incomesql),&conIncome,NULL)==SQLITE_OK) {
        int index1 = sqlite3_bind_parameter_index(conIncome, "@pa1");
        if(sqlite3_bind_text(conIncome, index1, ToDefaultConv(time_from), LenDefaultConv(time_from), SQLITE_STATIC)!=SQLITE_OK) {
            wxLogDebug(_T("sqlite3_bind_text on m_keyvalue_.first Error on. %s"), sqlite3_errmsg(g_db));
        }
        index1 = sqlite3_bind_parameter_index(conIncome, "@pa2");
        if(sqlite3_bind_text(conIncome, index1, ToDefaultConv(time_to), LenDefaultConv(time_to), SQLITE_STATIC)!=SQLITE_OK) {
            wxLogDebug(_T("sqlite3_bind_text on ntimeslot Error on. %s"), sqlite3_errmsg(g_db));
        }
        if(sqlite3_step(conIncome)==SQLITE_ROW) {
            if(sqlite3_column_text(conIncome,0)!=NULL) {
                wxLogDebug(_T("income %f"),dincome);
                dincome=sqlite3_column_double(conIncome,0);
            }
        }
    } else {
        wxLogDebug(_T("Error on sqlite3_prepare_v2: %s"), sqlite3_errmsg(g_db));
    }
    if (sqlite3_finalize(conIncome) != SQLITE_OK) {
        wxLogDebug(_T("Error on sqlite3_finalize: %s"), sqlite3_errmsg(g_db));
    }
    //支出查询
    if(sqlite3_prepare_v2(g_db,ToDefaultConv(expendsql),LenDefaultConv(expendsql),&conExpend,NULL)==SQLITE_OK) {
        int index1 = sqlite3_bind_parameter_index(conExpend, "@pa1");
        if(sqlite3_bind_text(conExpend, index1, ToDefaultConv(time_from), LenDefaultConv(time_from), SQLITE_STATIC)!=SQLITE_OK) {
            wxLogDebug(_T("sqlite3_bind_text on m_keyvalue_.first Error on. %s"), sqlite3_errmsg(g_db));
        }
        index1 = sqlite3_bind_parameter_index(conExpend, "@pa2");
        if(sqlite3_bind_text(conExpend, index1, ToDefaultConv(time_to), LenDefaultConv(time_to), SQLITE_STATIC)!=SQLITE_OK) {
            wxLogDebug(_T("sqlite3_bind_text on ntimeslot Error on. %s"), sqlite3_errmsg(g_db));
        }
        if(sqlite3_step(conExpend)==SQLITE_ROW) {
            if(sqlite3_column_text(conExpend,0)!=NULL) {
                dexpend=sqlite3_column_double(conExpend,0);
            }
        }
    } else {
        wxLogDebug(_T("Error on sqlite3_prepare_v2: %s"), sqlite3_errmsg(g_db));
    }
    if (sqlite3_finalize(conExpend) != SQLITE_OK) {
        wxLogDebug(_T("Error on sqlite3_finalize: %s"), sqlite3_errmsg(g_db));
    }
    //结余查询
    if(sqlite3_prepare_v2(g_db,ToDefaultConv(balancesql),LenDefaultConv(balancesql),&conBalance,NULL)==SQLITE_OK) {
        int index1 = sqlite3_bind_parameter_index(conBalance, "@pa1");
        if(sqlite3_bind_text(conBalance, index1, ToDefaultConv(time_from), LenDefaultConv(time_from), SQLITE_STATIC)!=SQLITE_OK) {
            wxLogDebug(_T("sqlite3_bind_text on m_keyvalue_.first Error on. %s"), sqlite3_errmsg(g_db));
        }
        index1 = sqlite3_bind_parameter_index(conBalance, "@pa2");
        if(sqlite3_bind_text(conBalance, index1, ToDefaultConv(time_to), LenDefaultConv(time_to), SQLITE_STATIC)!=SQLITE_OK) {
            wxLogDebug(_T("sqlite3_bind_text on ntimeslot Error on. %s"), sqlite3_errmsg(g_db));
        }
        if(sqlite3_step(conBalance)==SQLITE_ROW) {
            if(sqlite3_column_text(conBalance,0)!=NULL) {
                dbalance=sqlite3_column_double(conBalance,0);
            }
        }
    } else {
        wxLogDebug(_T("Error on sqlite3_prepare_v2: %s"), sqlite3_errmsg(g_db));
    }
    if (sqlite3_finalize(conBalance) != SQLITE_OK) {
        wxLogDebug(_T("Error on sqlite3_finalize: %s"), sqlite3_errmsg(g_db));
    }
    wxString csStat=wxString::Format(_T("总收入%g,总支出%g,总结余%g"),dincome,dexpend,dbalance);
    pText=wxDynamicCast(FindWindowById(IDC_EDIT_STATIC),wxTextCtrl);
    pText->SetValue(csStat);
    wxLogDebug(_T("OnBnClickedBtnSearch"));
}

void CDlgReportCash::OnBnClickedBtnExit(wxCommandEvent& event)
{
    Close();
    wxLogDebug(_T("OnBnClickedBtnExit"));
}

void CDlgReportCash::OnNMClickList(wxListEvent& event)
{
    if(event.GetIndex()==-1) {
        return;
    }
    wxListCtrl *pList=wxDynamicCast(FindWindowById(IDC_LIST),wxListCtrl);
    wxDateTime bir;
    if(bir.ParseDate(pList->GetItemText(event.GetIndex(),1))) {
        wxDatePickerCtrl *pDT=wxDynamicCast(FindWindowById(IDC_THEDAY),wxDatePickerCtrl);
        pDT->SetValue(bir);
    }
    long ntimeslot;
    pList->GetItemText(event.GetIndex(),2).ToLong(&ntimeslot);
    wxComboBox *pBox=wxDynamicCast(FindWindowById(IDC_COMBO_TIME),wxComboBox);
    pBox->SetSelection(ntimeslot-1);
    wxTextCtrl* pText=wxDynamicCast(FindWindowById(IDC_EDIT_BALANCE),wxTextCtrl);

    pText->SetValue(pList->GetItemText(event.GetIndex(),3));
    pText=wxDynamicCast(FindWindowById(IDC_EDIT_USER),wxTextCtrl);
    pText->SetValue(pList->GetItemText(event.GetIndex(),4));
    /////////////////////////////////////////////////////////////
    wxString strTmp=pList->GetItemText(event.GetIndex(),5);
    pBox=wxDynamicCast(FindWindowById(IDC_COMBO_TYPE),wxComboBox);
    pBox->SetValue(strTmp);
////////////////////////////////////////////////////////////////
    pText=wxDynamicCast(FindWindowById(IDC_RICHEDIT_REMARK),wxTextCtrl);
    pText->SetValue(pList->GetItemText(event.GetIndex(),6));
    wxLogDebug(_T("OnNMClickList"));
}
